package com.seeyon.ctp.rest.resources;


import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.brwh.service.SRMKanBanCgcblService;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.log.CtpLogFactory;
import org.apache.commons.logging.Log;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 采购成本率计算
 */
@Path("jssdk/SRMKB")
public class SRMKanBanCgcblResources  extends BaseResource {
    private static final Log LOG = CtpLogFactory.getLog(SRMKanBanCgcblResources.class);

    private SRMKanBanCgcblService sRMKanBanCgcblService = (SRMKanBanCgcblService) AppContext.getBean("sRMKanBanCgcblService");



    /**
     * 根据公司获取采购成本率
     * @return
     */
    @Path("getCGCBLByGS")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getCGCBLByGS(){
        HashMap<String, Object> map = new HashMap<>();
        try {
            Map<String, Object> cgcblByGS = sRMKanBanCgcblService.getCGCBLByGS();
            map.put("code","200");
            map.put("data",cgcblByGS);
            map.put("msg","");
        }catch (Exception e){
            LOG.info("根据公司获取采购成本率异常：",e);
            map.put("code","500");
            map.put("data",null);
            map.put("msg","根据公司获取采购成本率异常");
        }
        return this.ok(JSONObject.toJSONString(map));
    }



    /**
     * 根据品类获取采购成本率
     * @return
     */
    @Path("getCGCBLByPL")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getCGCBLByPL(){
        HashMap<String, Object> map = new HashMap<>();
        try {
            List<Map<String, Object>> cgcblByPL = sRMKanBanCgcblService.getCGCBLByPL();
            map.put("code","200");
            map.put("data",cgcblByPL);
            map.put("msg","");
        }catch (Exception e){
            LOG.info("根据品类获取采购成本率异常：",e);
            map.put("code","500");
            map.put("data",null);
            map.put("msg","根据品类获取采购成本率异常");
        }
        return this.ok(JSONObject.toJSONString(map));
    }

    /**
     * 根据采购工程师获取采购成本率
     * @return
     */
    @Path("getCGCBLByCGGCS")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getCGCBLByCGGCS(){
        HashMap<String, Object> map = new HashMap<>();
        try {
            List<Map<String, Object>> cgcblByPL = sRMKanBanCgcblService.getCGCBLByCGGCS();
            map.put("code","200");
            map.put("data",cgcblByPL);
            map.put("msg","");
        }catch (Exception e){
            LOG.info("根据采购工程师获取采购成本率异常：",e);
            map.put("code","500");
            map.put("data",null);
            map.put("msg","根据采购工程师获取采购成本率异常");
        }
        return this.ok(JSONObject.toJSONString(map));
    }
}
